﻿using System.Windows;
using System.Windows.Input;

using TraceView.UI.Entities;

namespace TraceView.UI.CustomControls
{
    /// <summary>
    /// Interaction logic for TraceItemToastControl.xaml
    /// </summary>
    public partial class TraceItemToastControl
    {
        public static readonly DependencyProperty TraceItemProperty =
            DependencyProperty.Register("TraceItem", typeof (TraceItem), typeof (TraceItemToastControl),
                                        new UIPropertyMetadata());

        public static readonly DependencyProperty ToastMessageProperty =
            DependencyProperty.Register("ToastMessage", typeof (string), typeof (TraceItemToastControl),
                                        new UIPropertyMetadata());

        public TraceItemToastControl()
        {
            InitializeComponent();
        }


        public string ToastMessage
        {
            get { return (string) GetValue(ToastMessageProperty); }
            set { SetValue(ToastMessageProperty, value); }
        }

        public static readonly RoutedEvent ToastItemClickEvent = EventManager.RegisterRoutedEvent("ToastItemClick",
            RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TraceItemToastControl));

        public event RoutedEventHandler ToastItemClick
        {
            add { AddHandler(ToastItemClickEvent, value); }
            remove { RemoveHandler(ToastItemClickEvent, value); }
        }

        public TraceItem TraceItem
        {
            get { return (TraceItem) GetValue(TraceItemProperty); }
            set { SetValue(TraceItemProperty, value); }
        }

        private void OnCloseClick(object sender, RoutedEventArgs e)
        {
            ForceHidden();
        }

        private void ToastMouseEnter(object sender, MouseEventArgs e)
        {
            Cursor = Cursors.Hand;
        }

        private void TextBlockMouseDown(object sender, MouseButtonEventArgs e)
        {
            if(ToastItemClickEvent!=null)
                RaiseEvent( new RoutedEventArgs(ToastItemClickEvent)); 
           
        }
    }
}